'use strict';
const db = uniCloud.database()
const diffTime = 8 * 60 * 60 * 1000;
// 获取指定的今天的时间戳
function getMsByDate(timeStr, dayStr) {
	return new Date(dayStr+' '+timeStr).getTime()-diffTime;
}
exports.main = async (event, context) => {
	let todayTime = getMsByDate('00:00:00',event.day);
	const skipCount = (event.page - 1) * event.size;
	const whereArr = {
		'company': `${event.company}` || '',
		'dayTime': todayTime
	};
  let collection = db.collection('company_collect').where(whereArr);
  
  const totalRes = await collection.count();
  let res = {};
  if (totalRes.total>0) {
  	res = await collection.skip(skipCount).limit(event.size).orderBy("createTime", "desc").get();
  }
  return {
  	page: event.page,
  	size: event.size,
  	total: totalRes.total || 0,
  	data: res.data || []
  };
};
